package com.dragon.english_practice_back.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.english_practice_back.entity.User;
import com.dragon.english_practice_back.service.UserService;
import com.dragon.english_practice_back.mapper.UserMapper;
import com.dragon.english_practice_back.util.PasswordUtil;
import org.springframework.stereotype.Service;

/**
* @author 伫倚
* @description 针对表【user】的数据库操作Service实现
* @createDate 2025-03-01 01:19:13
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Override
    public boolean updateName(int id, String name) {
        // 检查数据
        if (name == null || name.length() == 0)
            return false;
        // 检查id
        if (id <= 0)
            return false;
        // 查找数据
        User user = getBaseMapper().selectById(id);
        if (user == null)
            return false;
        user.setName(name);
        // 修改数据
        int result = getBaseMapper().updateById(user);
        return result > 0;
    }

    @Override
    public boolean updatePassword(int id, String password) {
        // 检查数据
        if (password == null || password.length() < 6)
            return false;
        // 检查id
        if (id <= 0)
            return false;
        // 查找数据
        User user = getBaseMapper().selectById(id);
        if (user == null)
            return false;
        user.setPassword(PasswordUtil.encode(password));
        // 修改数据
        int result = getBaseMapper().updateById(user);
        return result > 0;
    }
}




